{createAction} = require('redux-actions')
Toast = require('antd-mobile/lib/toast')

actions =
  getMenuStart:createAction('MENU_INFO/GET_MENU_START')
  getMenuCompleted:createAction('MENU_INFO/GET_MENU_COMPLETED')
  getMenuFail:createAction('MENU_INFO/GET_MENU_FAIL')
  fetchGetMenu:(name,token)->
    (dispatch)->
      dispatch actions.getMenuStart()
      str = "http://202.136.214.173/api/GetMenu?name=#{name}"
      # str = "http://172.16.46.161/api/GetMenu?name=#{name}"
      promise = fetch(str,{
                  method: 'GET'
                  mode: 'cors'
                  cache: 'default'
                  headers: {
                    token:token
                  }
                })
              .then (res)->
                debugger
                if res.ok is true
                  res.json()
                else
                  new Promise.reject()
              .then (json)->
                debugger
                dispatch actions.getMenuCompleted(json)
              .catch (err)->
                # errObj = new TypeError(err.message);
                dispatch actions.getMenuFail(errObj)


module.exports = actions
